package org.f0rb.demo.dao;

import java.io.Serializable;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2010-1-26
 * Time: 23:22:51
 * To change this template use File | Settings | File Templates.
 */
public interface DAO<T> {
    /**
     * Method save ...
     *
     * @param t of type T
     * @return Integer
     */
    Serializable save(T t);

    /**
     * Method delete ...
     *
     * @param t of type T
     */
    void delete(T t);

    /**
     * Method update ...
     *
     * @param t of type T
     */
    void update(T t);

    /**
     * Method get ...
     *
     * @param id of type Integer
     * @return T
     */
    T get(Integer id);

    /**
     * Method uniqueByProperty ...
     *
     * @param propertyName of type String
     * @param value of type Object
     * @return T
     */
    T uniqueByProperty(String propertyName, Object value);

    /**
     * Method listAll ...
     * @return List
     */
    List<T> listAll();

    /**
     * Method listByProperty ...
     *
     * @param propertyName of type String
     * @param value of type Object
     * @return List<T>
     */
    List<T> listByProperty(String propertyName, Object value);

    /**
     * Method listColumns ...
     *
     * @param columnNames of type String[]
     * @return List
     */
    List listColumns(String columnNames[]);

    //List findColumnByProperty(String columnNames[], String propertyName, Object value);    

    /**
     * Method page ...
     *
     * @param start of type int
     * @param limit of type int
     * @return List
     */
    List<T> page(int start, int limit);

    /**
     * Method pageByProperty ...
     *
     * @param propertyName of type String
     * @param value of type Object
     * @param start of type int
     * @param limit of type int
     * @return List<T>
     */
    List<T> pageByProperty(String propertyName, Object value, int start, int limit);

    /**
     * Method listPartByNamedQuery ...
     *
     * @param queryName of type String
     * @param values of type Object[]
     * @param start of type int
     * @param limit of type int
     * @return List
     */
    List<T> listPartByNamedQuery(String queryName, Object[] values, int start, int limit);

    /**
     * Method sizeByPropertyInTable ...
     *
     * @param cTableName of type String
     * @param propertyName of type String
     * @param value of type Object
     * @return long
     */
    Long sizeByPropertyInTable(String cTableName, String propertyName, Object value);

    /**
     * Method size returns the total rows of this DAO object.
     *
     * @return the total rows (type int) of this DAO object.
     */
    int size();

    /**
     * Method count returns the total rows of this DAO object.
     *
     * @return the total rows (type long) of this DAO object.
     */
     Long count();

    /**
     * Method getByIdInTable ...
     *
     * @param tableName of type String
     * @param id of type Object
     * @return Object
     */
    Object getByIdInTable(String tableName, Object id);


    /**
     * 计算数据库中的给定字段和给定值的记录的条数
     *
     * @param key 数据库中的字段名
     * @param value 所查询的字段的值
     * @return Object
     */
    Long countByProperty(String key, Object value);
}
